<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>关注领取优惠券</title>
  <link rel="stylesheet" href="src/index.css">
  <script src="../javascripts/jquery.min.js"></script>
  <script src="js/jquery.md5.js"></script>
</head>

<body style="background: url('images/backgrounp.jpg')">
  <div style="margin-top: 100px; ">
    <div class="box">
      <img class="ditu" src="images/jianbian.png" alt="">
      <div class="shopimage">
        <img src="images/timg2.jpeg" alt="">
      </div>
      <div class="shopname">
        <p class="shopname_name">天猫精灵官方旗舰店</p>
        <button class="shopname_apply" onclick="shopname_apply()">关注并领取优惠券</button>
      </div>
    </div>
  </div>

  <script>
    var hostname = location.hostname;
    var origin = '';
    if (hostname === 'localhost') {
      origin = 'http://localhost:3000';
    } else {
      origin = 'http://api.nicai360.com';
    }
    // 店铺收藏
    function shopname_apply() {
      getTaobaoSign({
        item_numid: "72421790",
        method: "taobao.favorite.add",
      }, function (result) {
        if (!result.error) {
          $.ajax({
            type: 'POST',
            url: 'https://eco.taobao.com/router/rest',
            data: result,
            success: function (result1) {
              if (!result1.error) {
                console.log(result1);
              } else {
                console.log(result1.msg);
              }
            }
          });
        }
      });
      // 领取优惠券
      getTaobaoSign({
        method: "taobao.promotion.coupon.apply",
        seller_id: "72421790",
        spread_id: "sdfdgerg56j6i7"
      }, function (result2) {
        if (!result2.error) {
          $.ajax({
            type: 'POST',
            url: 'https://eco.taobao.com/router/rest',
            data: result2,
            success: function (result3) {
              if (!result3.error) {
                console.log(result3)
              } else {
                console.log(result3.msg)
              }
            }
          })
        }
      })
      // 关注用户(达人)
      getTaobaoSign({
        method: "mtop.cybertron.follow.add",
        dataType: "jsonp",
        t: '1525341348491',
        ecode: '1',
        type: "jsonp",
        needLogin: true,
        callback: "mtopjsonp3",
        jsv: "2.4.3"
      }, function(result4) {
        if (!result4.error) {
          $.ajax({
            type: 'POST',
            url: 'https://eco.taobao.com/router/rest',
            data: result4,
            success: function (result5) {
              if (!result5.error) {
                console.log(result5)
              } else {
                console.log(result5.msg)
              }
            }
          })
        }
      })
    }
    function getTaobaoSign(data, callback) {
      $.ajax({
        type: "POST",
        url: origin + "/api/test/test",
        data: data,
        success: function (result) {
          if (!result.error) {
            callback(result);
          }
        }
      })
    }
  </script>

</body>

</html>